package china.accountinghelper.adapter;

import china.wc.tallyhelper.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AdapterGridViewIndexMenu extends BaseAdapter
{
    // 上下文对象
    private Context  mContext;
    // 图标
    private int[]    mImageSource;
    // 图标下的文字
    private String[] mTextSource;

    public AdapterGridViewIndexMenu(Context pContext)
    {
        super();
        mContext = pContext;
        this.mImageSource = new int[] {
                R.drawable.main_nav_icon_setting,
                R.drawable.main_nav_icon_report,
                R.drawable.main_nav_icon_yeartrans,
                R.drawable.main_nav_icon_account,
                R.drawable.main_nav_icon_budget,
        };

        mTextSource = pContext.getResources().getStringArray(R.array.index);
    }

    // 返回数据源的长度
    @Override
    public int getCount()
    {
        return mImageSource.length;
    }

    //
    @Override
    public Object getItem(int position)
    {
        return mImageSource[position];
    }

    //
    @Override
    public long getItemId(int position)
    {

        return position;
    }

    // 返回绑定好图片和文字的TextView
    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {

        if (convertView == null) {
            convertView = LayoutInflater.from(this.mContext).inflate(R.layout.item_gridview_indexmenu, null);
        }

        TextView _TextViewMenuItem = (TextView) convertView.findViewById(R.id.ItemGridViewIndexmenu_TextView_MenuItem);
        _TextViewMenuItem.setCompoundDrawablesWithIntrinsicBounds(0, this.mImageSource[position], 0, 0);
        _TextViewMenuItem.setText(this.mTextSource[position]);

        return convertView;
    }

}
